// pages/student/qiandao/detail.js
// var wxCharts = require('../../common/wxcharts');
// import {
//   wxCharts
// } from "../../../utils/dist_wxcharts.js";
import {
  yichuqin,
  weichuqin
} from "../../../api/student";
import {
  parseTime
} from "../../../utils/datetime.js";
let CHARTS = require('../../../utils/dist_wxcharts.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classid: '',
    classanme: '',
    banji: {},
    count1:'',
    count2:'',
    arr: [{
      name: '未出勤',
      data: 0
    }, {
      name: '已出勤',
      data: 0
    }],
    weichuqin: [],
    yichuqin: [],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.channel = this.getOpenerEventChannel()
    this.channel.on("send", banji => {
      // let classid = res["classid"]
      this.setData({
        classid: banji.classid,
        classname: banji.classname
      })
      wx.setNavigationBarTitle({
        title: banji.classname,
      })
    })
    this.myPie()
    this.loadData()
  },
  loadData: function () {
    let data = {
      classid: this.data.classid
    }
    yichuqin(data).then(res => {
      if (res == null) {
        this.setData({
          yichuqin: '还未出勤',
        })
      } else {
        res.data.forEach(item => {
          item.time = parseTime(item.time, "{y}/{m}/{d} {h}:{i}:{s}")
          // console.log("timeeeeeeeeeeeee", item.time)
        })
        let yichuqin = res.data
        let count1=yichuqin.length
        this.data.arr[1].data=count1
        console.log("yichuqincount",this.data.arr[1].data)
        console.log("yiqian", yichuqin)
        this.setData({
          yichuqin: yichuqin,
        })
      }
    })
    weichuqin(data).then(res => {
      if(res==null){
        this.setData({
          weichuqin: '还未出勤',
        })
      }else{
        res.data.forEach(item => {
          item.create_time = parseTime(item.create_time, "{y}/{m}/{d} {h}:{i}:{s}")
          // console.log("timeeeeeeeeeeeee",item.create_time)
        })
        let weichuqin = res.data
        let count2=yichuqin.length
        this.data.arr[0].data=count2
        console.log("weichuqincount2222",this.data.arr[0].data)
        console.log(weichuqin)
        this.setData({
          weichuqin: weichuqin,
        })
      }
    })
  },

  myPie: function () {
    new CHARTS({
      // component: this,
      canvasId: 'canvas1',
      type: 'pie',
      series: this.data.arr,
      width: 300,
      height: 300,
      dataLabel: true,
    });
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})